package com.daiziru.wuyanmall.service.impl;

import com.daiziru.wuyanmall.dao.UserAddrMapper;
import com.daiziru.wuyanmall.entity.UserAddr;
import com.daiziru.wuyanmall.service.UserAddrService;
import com.daiziru.wuyanmall.vo.ResultStatus;
import com.daiziru.wuyanmall.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 作者：無言
 * 时间：2022/3/10 21:44
 * 描述：永无BUG
 */
@Service
public class UserAddrServiceImpl implements UserAddrService {
    @Autowired
    private UserAddrMapper userAddrMapper;


    @Override
    @Transactional(propagation = Propagation.SUPPORTS)//设置事务隔离级别
    public ResultVO listAddrsByUid(int userId) {
        Example example = new Example(UserAddr.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("userId", userId);
        criteria.andEqualTo("status", 1);
        List<UserAddr> userAddrs = userAddrMapper.selectByExample(example);
        ResultVO resultVO = new ResultVO(ResultStatus.OK, "success", userAddrs);
        return resultVO;
    }
}
